home *** CD-ROM | disk | FTP | other *** search
- Path: engnews1.Eng.Sun.COM!taumet!clamage
- From: Martin Aupperle <100754.2730@CompuServe.COM>
- Newsgroups: comp.std.c++
- Subject: Ambiguity when overloading operators
- Date: 11 Apr 1996 23:50:24 GMT
- Organization: ?
- Approved: clamage@eng.sun.com (comp.std.c++)
- Message-ID: <960411233436_100754.2730_GHV68-1@CompuServe.COM>
- NNTP-Posting-Host: taumet.eng.sun.com
- Content-Length: 629
- X-Lines: 31
- Originator: clamage@taumet
-
- If I define
-
- struct X {
-
- X( int );
- operator const char* () const;
-
- /* other members */
- };
-
- X& operator + ( const X&, const X& );
-
- I cannot say
-
- X x1( 5 );
- X x2 = x1+3; // ambiguous
-
- Borland BC4.5 says that x1+3 is ambiguous. I know that it can
- 1. convert 3 to an X and call operator + ( const X&, constX& )
- 2. convert x1 to a const char* and do pointer arithmetics.
-
- Is the compiler right? I have in mind that a conversion towards a user defined
- type has precedence over the conversion to a fundamental type. So choice (1)
- should be right and it shoud not be ambiguous.
-
- Am I correct?
- Martin
-
-
-
- [ comp.std.c++ is moderated. To submit articles: try just posting with ]
- [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
- [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
- [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
- [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
-